package com.xing.jvmsandbox;

import com.xing.jvmsandbox.event.BeforeEvent;
import com.xing.jvmsandbox.event.Event;
import com.xing.jvmsandbox.listener.EventListener;
import com.xing.jvmsandbox.weave.test.Computer;

public class AOPMain {

    public static void main(String[] args) throws Throwable {
        AOP aop = new AOP.Builder().
                targetClass(Computer.class)
                .targetMethodName("sum")
                .eventListener(new EventListener() {
                    @Override
                    public void onEvent(Event event) throws Throwable {
                        if(event instanceof BeforeEvent) {
                            final BeforeEvent beforeEvent = (BeforeEvent) event;
                            System.err.println("hello 我进来了");
                            final int[] numberArray = (int[]) beforeEvent.argumentArray[0];
                            System.err.println(numberArray[0]);
                            System.err.println(numberArray[1]);
                        }
                    }
                })
                .build();

        Computer computer = (Computer) aop.create();
        computer.sum(new int[]{1,1});
    }
}
